<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" +
			request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>头像修改</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<link rel="shortcut icon" href="<%=basePath%>static/favicon.ico" type="image/x-icon"/>
	<link rel="stylesheet" href="<%=basePath%>static/css/font.css">
	<link rel="stylesheet" href="<%=basePath%>static/css/xadmin.css">
	<script type="text/javascript" src="<%=basePath%>static/js/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath%>static/lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="<%=basePath%>static/js/xadmin.js"></script>
	<script type="text/javascript" src="<%=basePath%>static/js/ajaxfileupload.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>

<body>
<div class="x-body">
	<form class="layui-form" id="updata_form" enctype="multipart/form-data">
		<div class="layui-form-item">
			<label for="userImg" class="layui-form-label">
			</label>
			<div class="layui-input-inline">
				<input type="file" id="userImg" name="userImg" required="" lay-verify="userAccount"
					   autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label for="changeImg" class="layui-form-label">
			</label>
			<button class="layui-btn" id="changeImg" type="button">
				修改
			</button>
		</div>
	</form>
</div>

<script>
    $("#changeImg").click(function () {
        if($("#userImg").val()===""){
            layer.alert("请选择文件！！！");
            return;
		}
		$.ajaxFileUpload({
            url:"<%=basePath%>user/updataUserImg",
            fileElementId:"userImg",
            type: "get",
            dataType:"text",
			data:{"userAccount":localStorage.getItem("userAccount")},
            secureuri : false,
            success:function (data,status) {
                console.log(data);
                alert("文件上传成功");
                if(data!=null){
                    //获取当前frame
                    var index=parent.layer.getFrameIndex(window.name);
                    //关闭
                    parent.layer.close(index);
                    //刷新
                    parent.location.reload();
				}
            }, error:function (data,status,e) {
                alert("服务器错误");
            },
        });
    })
</script>
</body>
</html>